package edu.zut.filter;

import javax.servlet.*;
import java.io.IOException;

public class FilterDemo implements Filter {

    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
        System.out.println("demo1初始化.....");
    }

    /**
     * 过滤器的执行
     * @param request  请求
     * @param response 响应
     * @param chain    过滤器链
     * @throws IOException
     * @throws ServletException
     */
    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
        System.out.println("demo1的过滤执行逻辑");
        //用户的url请求被拦截之后，如果不符合要求，需要返回   重定向或转发
        //符合过滤要求，如何放行当前url
        chain.doFilter(request, response);
    }

    @Override
    public void destroy() {
        System.out.println("demo1销毁......");
    }
}
